home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 34 / Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso / -seriously_amiga- / programming / basic / blitzc2p / game / rupture / display.ascii next >
Text File  |  1998-10-01  |  26KB  |  1,106 lines

  1.  
  2. ;Display
  3.  
  4. Statement Permit{}
  5. ;Permit multitasking, only if it is globally intended
  6.   SHARED Multitasking.b
  7.   If Multitasking Then Permit_
  8. End Statement
  9.  
  10. Statement Forbid{}
  11. ;Disable multitasking, if it isn't globally intended
  12.   SHARED Multitasking.b
  13.   If Multitasking Then Forbid_
  14. End Statement
  15.  
  16. Statement Multitasking{State.b}
  17. ;Toggle global multitasking on or off.
  18.   SHARED Multitasking.b
  19.   If State
  20.     If Multitasking=False Then Permit_
  21.   Else
  22.     If Multitasking Then Forbid_
  23.   EndIf
  24.   Multitasking=State
  25. End Statement
  26.  
  27. Statement InitC2P{A.l,B.l,C.l,D.b}
  28. ;Initialises chunky-to-planar
  29. ;A.l=d0=Chunky Width
  30. ;B.l=d1=Chunky Height
  31. ;C.l=d2=Chunky Yoffset (Top)
  32. ;D.b=d3=Processor (blitz instruction, will be 0/1/2/3/4)
  33.   LEA     c2p_Data(pc),a0
  34.   ANDI.l  #$ffff,d0
  35.   MULU.w  d0,d2
  36.   LSR.l   #3,d2 ; bytes
  37.   MOVE.l  d2,c2p_ScrOffs-c2p_Data(a0) ; Planar Y offset
  38.   MULU.w  d0,d1
  39.   MOVE.l  d1,c2p_Pixels-c2p_Data(a0)
  40.   CMP.b   #4,d3 ; 040+?
  41.   BNE     c2pIlowCPU
  42.   MOVE.b  #1,c2pCPUmode
  43.   BRA     c2pIskip
  44. c2pIlowCPU
  45.   MOVE.b  #0,c2pCPUmode
  46. c2pIskip
  47. AsmExit
  48. End Statement
  49.  
  50. Statement ChunkyClearscreen4{ChunkyBuf.l,BufHeight.w,OpWidth.w,DestWidth.w,Value.l}
  51. ;Clears the rightmost 4-pixel-width column in the chunky buffer to Value.l
  52. ;Covers up the longword clip/wrap buffer. Column is rightmost to OpWidth, DestWidth supplies modulo
  53.   MOVE.l  d0,a0 ; Chunky output
  54.   AND.l   #$FFFF,d1 ; Only word
  55.   SUBQ.l  #1,d1 ; Loopcounter
  56.   AND.l   #$FFFF,d3 ; Modulo
  57.   SUBQ.l  #4,d3 ; Modulo-4 to accomodate move.l
  58.   AND.l   #$FFFF,d2 ; Only word
  59.   SUBQ.l  #4,d2 ; OpWidth-4, x start position
  60.   ADD.l   d2,a0 ; Source position
  61. ChunkyClear4
  62.   MOVE.l  d4,(a0)+ ; Clear 4 pixels
  63.   ADD.l   d3,a0 ; Dest Modulo
  64.   DBRA    d1,ChunkyClear4
  65.   AsmExit
  66. End Statement
  67.  
  68. Statement ChunkyClearscreen32{ChunkyBuf.l,BufHeight.w,Value.l,Width.w}
  69. ;Clears chunky screen, Width*BufHeight pixels (Width multiples of 32!)
  70.   MOVE.l  a3,-(a7)
  71.   MOVE.l  d0,a0 ; Chunky output
  72.   MOVE.l  d2,d0 ; Get value
  73.   AND.l   #$FFFF,d3 ; Only word
  74.   MOVE.l  d3,d2 ; Width
  75.   AND.l   #$FFFF,d1 ; Only word
  76.   MULU    d1,d2 ; Size in bytes
  77.   ADD.l   d2,a0 ; To end of buffer
  78.   SUBQ.l  #1,d1 ; Init YLoop
  79.   EXG.l   d0,d3 ; 1
  80.   MOVE.l  d3,d4 ; 2
  81.   MOVE.l  d3,d5 ; 3
  82.   MOVE.l  d3,d6 ; 4
  83.   MOVE.l  d3,d7 ; 5
  84.   MOVE.l  d3,a1 ; 6
  85.   MOVE.l  d3,a2 ; 7
  86.   MOVE.l  d3,a3 ; 8 longwords = 32 pixels
  87.   LSR.w   #2+3,d0 ; Width in longwords (2=2^2=4=longwords, 3=2^3=8=groups of 8 longwords)
  88.   SUBQ.l  #1,d0 ; Xloopcounter
  89. ChunkyClrLoopY
  90.     MOVE.l  d0,d2 ; Init XLoop
  91. ChunkyClrLoopX
  92.       MOVEM.l d3-d7/a1-a3,-(a0) ; Clear 32 pixels
  93.       DBRA    d2,ChunkyClrLoopX
  94.     DBRA    d1,ChunkyClrLoopY
  95.   MOVE.l  (a7)+,a3
  96.   AsmExit
  97. End Statement
  98.  
  99. Statement ChunkyCopy16{ChunkyBufA.l,ChunkyBufB.l,BufHeight.w,CPU.b,OpWidth.w,DestWidth.w}
  100. ;Copies one chunky screen to another, Width*BufHeight pixels (Width multiples of 16!)
  101. ;Seperate routines for 040+ (move16) and 030- (movem)
  102. ;Width of source buffer and dest buffer will be the same and use the same modulo but OpWidth can be narrower
  103.   MOVE.l  d0,a0   ; Chunky source
  104.   MOVE.l  d1,a1   ; Chunky destination
  105.   MOVE.w  d2,d0   ; Height
  106.   AND.l   #$FFFF,d0 ; Only word
  107.   SUBQ.l  #1,d0   ; d0=YLoop
  108.   AND.l   #$FFFF,d4 ; Only word
  109.   AND.l   #$FFFF,d5 ; Only word
  110.   SUB.l   d4,d5   ; Dest modulo
  111.   LSR.w   #2+2,d4   ; Longwords (2=2^2=4=longwords, 2=2^2=4=groups of 4 longwords
  112.   SUBQ.l  #1,d4   ; loop
  113.   MOVE.l  d4,d1   ; d1=XLoop
  114.   MOVE.l  d5,d2   ; d2=Dest Modulo
  115.   CMP.b   #4,d3   ; 040+?
  116.   BEQ     ChunkyCopy040 ; Yes, do move16's
  117.   ADD.l   #16,a1
  118. ChunkyCopy030
  119. ChunkyCopy030y
  120.     MOVE.l  d1,d3 ; d3=Xloop
  121. ChunkyCopy030x
  122.       MOVEM.l (a0)+,d4-d7
  123.       MOVEM.l d4-d7,-(a1) ; 16 pixels
  124.       ADD.l   #32,a1
  125.       DBRA    d3,ChunkyCopy030x
  126.     ADD.l   d2,a0   ; Source modulo
  127.     ADD.l   d2,a1   ; Dest modulo
  128.     DBRA    d0,ChunkyCopy030y
  129.   AsmExit
  130. ChunkyCopy040
  131. ChunkyCopy040y
  132.     MOVE.l  d1,d3 ; d3=Xloop
  133. ChunkyCopy040x
  134.       Dc.l    $F6209000 ; move16 (a0)+,(a1)+ ; 16 bytes
  135.       DBRA    d3,ChunkyCopy040x
  136.     ADD.l   d2,a0   ; Source modulo
  137.     ADD.l   d2,a1   ; Dest modulo
  138.     DBRA    d0,ChunkyCopy040y
  139.   AsmExit
  140. End Statement
  141.  
  142. Function.b InitDisplay{Title$}
  143. ;Creates a display
  144. ;Title$=The screen title (not displayed)
  145.   SHARED PrefDisplayHeight.w,PrefDisplayID.l,PrefDisplayBuffering.b,ChunkyHeight.w,*ScrVP.ViewPort,IsAGA.b
  146.   SHARED ChunkyBase.l,ChunkyBuffer.l,LandBuffer.l,GameHeight.w,PrefDisplayLeft.w,PrefDisplayTop.w
  147.   SHARED PrefDisplayDepth.w,ChunkyWidth.w,PrefDisplayWidth.w,DisplaySplit.w,GameWidth.w
  148.   SHARED GameChunkyWidth.w,GameChunkyHeight.w
  149.   ;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
  150.   ;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
  151.   Dim ScrTags.TagItem(13)
  152.   Rect.Rectangle\MinX=0,0,320,240 ; For test
  153.   ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
  154.   ScrTags(1)\ti_Tag=#SA_Height,240; For test
  155.   ScrTags(2)\ti_Tag=#SA_Depth,PrefDisplayDepth
  156.   ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  157.   ScrTags(4)\ti_Tag=#SA_Type,$F
  158.   ScrTags(5)\ti_Tag=#SA_Quiet,True
  159.   ScrTags(6)\ti_Tag=#SA_ShowTitle,False
  160.   ScrTags(7)\ti_Tag=#SA_Behind,True
  161.   ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
  162.   ScrTags(9)\ti_Tag=#SA_Exclusive,True
  163.   ScrTags(10)\ti_Tag=#SA_Draggable,False
  164.   ScrTags(11)\ti_Tag=#SA_AutoScroll,True
  165.   ScrTags(12)\ti_Tag=#TAG_DONE,0
  166.   ScrTags(13)\ti_Tag=#TAG_DONE,0
  167.   InitShape 0,16,1,2 ; Mouse pointer 16x1 (transparent)
  168.   UsedChip.l=(320 LSR 3)*PrefDisplayDepth*240 ; With test params
  169.   FreeChip.l=AvailMem_(#MEMF_CHIP)
  170.   Forbid{}
  171.   If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
  172.     NowChip.l=AvailMem_(#MEMF_CHIP)
  173.     Permit{}
  174.     If FreeChip-NowChip<UsedChip
  175.       ; Graphics card screen
  176.       IsAGA=False
  177.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  178.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  179.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
  180.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  181.       VWait 25 ; seems to be necessary (safer)
  182.       Free Screen 0
  183.       VWait 10 ; just to be on the safe side
  184.       If ScreenTags(0,Title$,&ScrTags(0))<>0
  185.         For Loop.w=0 To PrefDisplayBuffering-1
  186.           If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  187. If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  188.           WPointer 0
  189.           Menus Off
  190.           ScreensBitMap 0,Loop
  191.           *TmpBmp.bitmap=Addr BitMap(Loop)
  192.           Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
  193.           For DLoop.w=0 To PrefDisplayDepth-1
  194.             *TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
  195.           Next DLoop
  196.         Next Loop
  197.       Else
  198.         Function Return False
  199.       EndIf
  200.     Else
  201.       ; AGA screen
  202.       IsAGA=True
  203.       PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
  204.       If (PrefDisplayWidth*PrefDisplayHeight) LSR 3>#PlaneSize
  205.         PrefDisplayHeight=Int(#PlaneSize/(PrefDisplayWidth LSR 3))
  206.       EndIf
  207.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  208.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  209.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
  210.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  211.       Forbid{}
  212.       VWait 25 ; seems to be necessary (safer)
  213.       Free Screen 0
  214.       For Loop.w=0 To PrefDisplayBuffering-1
  215.         If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  216.         If AvailMem_(#MEMF_CHIP)>=(#PlanarWidth*#PlanarHeight)+16
  217.           Memory.l=AllocMem((#PlanarWidth*#PlanarHeight)+16,$10002) ; Chip bitmap
  218.           Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
  219.           If Memory<>0
  220.             CludgeBitMap Loop,#PlanarWidth,#PlanarHeight,PrefDisplayDepth,Memory
  221.             *TmpBmp.bitmap=Addr BitMap(Loop)
  222.             *TmpBmp\_height=PrefDisplayHeight ; Force display height
  223.             *TmpBmp\_ebwidth=PrefDisplayWidth LSR 3 ; Force display width
  224.             *TmpBmp\_bitplanemod=((#PlanarWidth*#PlanarHeight)-(PrefDisplayWidth*PrefDisplayHeight)) LSR 3 ; Force plane modulo
  225.             If Loop=0
  226.               ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
  227.               If ScreenTags(0,Title$,&ScrTags(0))=0
  228.                 Permit{}
  229.